package com.tc.modules.sys.service.impl;

import com.tc.common.model.vo.UserVo;
import com.tc.common.utils.UserUtils;
import com.tc.model.dto.SysUserInfoDto;
import com.tc.modules.sys.mapper.SysUserMapper;
import com.tc.modules.sys.model.dto.SysSystemDto;
import com.tc.modules.sys.model.entity.SysDept;
import com.tc.modules.sys.model.entity.SysRole;
import com.tc.modules.sys.model.entity.SysUser;
import com.tc.modules.sys.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: tianchao
 * @Date: 2020/4/22 15:34
 * @Description:
 */
@Service
public class SysUserServiceImpl implements ISysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private ISysUserRoleService sysUserRoleService;

    @Autowired
    private ISysUserDeptService sysUserDeptService;

    @Autowired
    private ISysRoleResourceService sysRoleResourceService;

    @Autowired
    private ISysResourceService sysResourceService;

    @Autowired
    private ISysSystemService iSysSystemService;

    /**
     * 根据登陆用户名获取用户登陆信息
     *
     * @param username 登陆用户名
     * @return 用户登陆信息
     */
    @Override
    public UserVo loadUserByUsername(String username) {
        return sysUserMapper.loadUserByUsername(username);
    }

    /**
     * 根据用户登陆名称获取用户信息
     *
     * @return sysUserInfoDto
     */
    @Override
    public SysUserInfoDto getCurrentUserInfo() {
        SysUser user = this.selectByUsername(UserUtils.getUser());
        if (user == null){
            return null;
        }
        List<SysRole> roleList = sysUserRoleService.selectRoleByUserId(user.getId());
        List<SysDept> deptList = sysUserDeptService.selectDeptByUserId(user.getId());
        List<String> permissionList = sysRoleResourceService.selectPermissionByRoles(roleList);
        List<SysSystemDto> systemList = sysResourceService.guideInfo();
        boolean isGuide = iSysSystemService.haveGuide();
        return null;
    }

    private SysUser selectByUsername(String username){
        return sysUserMapper.selectOne(new SysUser().setUsername(username));
    }
}
